/*
 * MySql.h
 *
 *  Created on: Jul 3, 2024
 *      Author: root
 */

#ifndef BSP_SQL_MYSQL_H_
#define BSP_SQL_MYSQL_H_
#include <mysql/mysql.h>
#include "basic_header.h"

namespace bsp {

class MySql {
private:
	int max_conn;
	std::queue<MYSQL*> que, que_save;

	std::string host, user, pwd, dbname;
	int port;

public:
	MySql(const char *host, int port, const char *user, const char *pwd,
			const char *dbname, int max_conn);

	virtual ~MySql();

	int open();
	void close();

	MYSQL* getConn();

	uint32_t getAvalableCount() {
		return que.size();
	}

	void freeConn(MYSQL *ptr);
};

} /* namespace bsp */

#endif /* BSP_SQL_MYSQL_H_ */
